// pages/shebao/paydetail/paydetail.js

var choseCity = require("../../../../utils/formula");
const utils = require("../../../../utils//util");
let toggleCollection = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    city: "深圳",
    project: ["项目", "个人缴纳(元）", "单位缴纳(元）"],
    scroll: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // utils.colleation(this, "社保缴费计算");
    toggleCollection = true;
    this.setData({
      computeData: JSON.parse(options.computeData),
    });

    this.computePayment(this.data.computeData);
  },

  computePayment(computeData) {
    const formula = new choseCity.Formula(this.data.city);
    let yanglao = formula.yanglao(computeData.basePayment, computeData.register);
    let medicare = formula.medicare(computeData.basePayment, computeData.level);
    let injury = formula.injury(computeData.basePayment);
    let birthInsure = formula.birthInsure(computeData.basePayment);
    let shiye = formula.shiye(2200);

    let personSum = parseFloat(yanglao.person_p) + parseFloat(medicare.person_h) + parseFloat(injury.person_e) + parseFloat(birthInsure.person_m) + parseFloat(shiye.person_u);
    let comidSum = parseFloat(yanglao.comid_p) + parseFloat(medicare.comid_h) + parseFloat(injury.comid_e) + parseFloat(birthInsure.comid_m) + parseFloat(shiye.comid_u);
    let paymentAll = personSum + comidSum;

    this.setData({
      details: [
        { name: '养老保险', person: yanglao.person_p, comid: yanglao.comid_p },
        { name: '医疗保险', person: medicare.person_h, comid: medicare.comid_h },
        { name: '工伤保险', person: injury.person_e, comid: injury.comid_e },
        { name: '生育保险', person: birthInsure.person_m, comid: birthInsure.comid_m },
        { name: '失业保险', person: shiye.person_u, comid: shiye.comid_u },
      ],
      personSum: personSum.toFixed(2),
      comidSum: comidSum.toFixed(2),
      paymentAll: paymentAll.toFixed(2),
    })

  },
  onPageScroll() {
    if (toggleCollection) {
      this.setData({
        scroll: true,
      });
      toggleCollection = false;
    }

  },
  closeCollection() {
    toggleCollection = false;
  },
  openCollection() {
    toggleCollection = true;
  }

  /**
   * 用户点击右上角分享
   */
})